package main

import (
	"context"
	"fmt"
	"go.uber.org/zap"
	"heightFive/Day_exam/day3/userApi/global"
	_ "heightFive/Day_exam/day3/userApi/initialize"
	"log"
	"net/http"
	"os"
	"os/signal"
	"time"
)

func main() {
	zap.S().Infow(
		"Api启动成功：：：",
		zap.String("Host", "0.0.0.0"),
		zap.Int("Port", 9091),
	)
	srv := &http.Server{
		Addr:    fmt.Sprintf(":%d", global.GlobalConfig.Service.Port),
		Handler: global.Router,
	}

	go func() {
		if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
			log.Printf("listen: %s\n", err)
		}
	}()

	quit := make(chan os.Signal)
	signal.Notify(quit, os.Interrupt)
	<-quit
	log.Println("Shutdown Server ...")
	ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
	defer cancel()
	if err := srv.Shutdown(ctx); err != nil {
		log.Fatal("Server Shutdown:", err)
	}
	log.Println("Server exiting")
}
